const express = require('express');
const fs = require('fs');
const app = express();
const path = require('path');

app.get('/excelData', async (req, res) => {
  
    try {
        const data = fs.readFileSync('./static/data.json', 'utf-8');
    
        return res.send({
            code: 200,
            result: JSON.parse(data)
        })
    } catch(e) {
        console.error('接口请求失败:\n', e);
        res.send({
            code: 500,
            result: {
                header: [],
                data: []
            }
        })
    }
   
});

app.use(express.static(path.join(__dirname, 'public')));

app.get('/html', (req, res) => {
    try {
        res.sendFile(path.join(__dirname, 'public', 'index.html'));
    } catch(e) {
        console.error('前端页面获取失败:\n', e);
    }
})

app.listen(10009, () => {
    console.log('服务启动')
})